<template>
  <div class="mod-home">
    <div class="platform-header">
      <h1 class="platform-title">Python学习平台</h1>
      <p class="subtitle">从基础语法到高级应用，一站式Python学习体验</p>
      <div class="floating-python-icon">🐍</div>
    </div>

    <div class="feature-cards">
      <!-- 在线学习 -->
      <el-card class="feature-card" shadow="hover" @mouseenter="hoverCard(0)" @mouseleave="resetCard">
        <div slot="header" class="card-header">
          <i class="el-icon-notebook-2 card-icon"></i>
          <span>在线学习</span>
        </div>
        <div class="card-content">
          <p>系统化学习Python编程知识</p>
          <div class="feature-items">
            <div class="feature-item" v-for="(item, index) in features[0].items" :key="index">
              <i :class="item.icon"></i>
              <span>{{ item.text }}</span>
            </div>
          </div>
        </div>
        <div class="card-footer" :class="{active: activeCard === 0}">
          <el-button type="text" @click="navigateTo('/learn')">开始学习 →</el-button>
        </div>
      </el-card>

      <!-- 练习一下 -->
      <el-card class="feature-card" shadow="hover" @mouseenter="hoverCard(1)" @mouseleave="resetCard">
        <div slot="header" class="card-header">
          <i class="el-icon-edit-outline card-icon"></i>
          <span>练习一下</span>
        </div>
        <div class="card-content">
          <p>通过练习巩固所学知识</p>
          <div class="feature-items">
            <div class="feature-item" v-for="(item, index) in features[1].items" :key="index">
              <i :class="item.icon"></i>
              <span>{{ item.text }}</span>
            </div>
          </div>
        </div>
        <div class="card-footer" :class="{active: activeCard === 1}">
          <el-button type="text" @click="navigateTo('/practice')">开始练习 →</el-button>
        </div>
      </el-card>

      <!-- 计算 -->
      <el-card class="feature-card" shadow="hover" @mouseenter="hoverCard(2)" @mouseleave="resetCard">
        <div slot="header" class="card-header">
          <i class="el-icon-calculator card-icon"></i>
          <span>科学计算</span>
        </div>
        <div class="card-content">
          <p>强大的计算工具支持</p>
          <div class="feature-items">
            <div class="feature-item" v-for="(item, index) in features[2].items" :key="index">
              <i :class="item.icon"></i>
              <span>{{ item.text }}</span>
            </div>
          </div>
        </div>
        <div class="card-footer" :class="{active: activeCard === 2}">
          <el-button type="text" @click="navigateTo('/calculate')">开始计算 →</el-button>
        </div>
      </el-card>

      <!-- Web开发 -->
      <el-card class="feature-card" shadow="hover" @mouseenter="hoverCard(3)" @mouseleave="resetCard">
        <div slot="header" class="card-header">
          <i class="el-icon-monitor card-icon"></i>
          <span>Web开发</span>
        </div>
        <div class="card-content">
          <p>全栈开发实践平台</p>
          <div class="feature-items">
            <div class="feature-item" v-for="(item, index) in features[3].items" :key="index">
              <i :class="item.icon"></i>
              <span>{{ item.text }}</span>
            </div>
          </div>
        </div>
        <div class="card-footer" :class="{active: activeCard === 3}">
          <el-button type="text" @click="navigateTo('/web')">开始开发 →</el-button>
        </div>
      </el-card>
    </div>

    <div class="welcome-section">
      <h2>欢迎使用Python学习平台</h2>
      <p class="welcome-text">
        本平台提供从Python基础到高级应用的完整学习路径，包含丰富的学习资源、
        实践练习和实用工具，帮助您系统掌握Python编程技能。
      </p>
      <div class="floating-code">
        <span v-for="(char, index) in floatingCode" :key="index" :style="{animationDelay: `${index*0.1}s`}">
          {{ char }}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      activeCard: null,
      floatingCode: 'print("Hello, Python!")',
      features: [
        {
          items: [
            { icon: 'el-icon-document', text: 'Python基本语法' },
            { icon: 'el-icon-cpu', text: '算法知识学习' }
          ]
        },
        {
          items: [
            { icon: 'el-icon-tickets', text: 'Python基本语法练习' },
            { icon: 'el-icon-data-analysis', text: '算法题目训练' }
          ]
        },
        {
          items: [
            { icon: 'el-icon-help', text: '科学计算器' },
            { icon: 'el-icon-set-up', text: '矩阵运算' },
            { icon: 'el-icon-odometer', text: '科学计算' }
          ]
        },
        {
          items: [
            { icon: 'el-icon-reading', text: 'Web知识学习' },
            { icon: 'el-icon-c-scale-to-original', text: '在线Web运行' }
          ]
        }
      ]
    }
  },
  methods: {
    hoverCard(index) {
      this.activeCard = index
    },
    resetCard() {
      this.activeCard = null
    },
    navigateTo(path) {
      this.$router.push(path)
    }
  }
}
</script>

<style scoped>
.mod-home {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
}

.platform-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 40px 0;
  background: linear-gradient(135deg, #4CAF50 0%, #2E7D32 100%);
  color: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(46, 125, 50, 0.3);
  position: relative;
  overflow: hidden;
}

.platform-title {
  font-size: 2.8rem;
  margin-bottom: 15px;
  position: relative;
  z-index: 2;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
  animation: fadeInDown 0.8s ease;
}

.subtitle {
  font-size: 1.3rem;
  opacity: 0.9;
  position: relative;
  z-index: 2;
  animation: fadeIn 1s ease 0.3s both;
}

.floating-python-icon {
  position: absolute;
  font-size: 8rem;
  opacity: 0.1;
  animation: float 6s ease-in-out infinite;
  z-index: 1;
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 25px;
  margin-bottom: 40px;
}

.feature-card {
  transition: all 0.3s ease;
  border-radius: 10px;
  border: none;
  overflow: hidden;
  transform: translateY(0);
  background: linear-gradient(to bottom, #ffffff, #f5f5f5);
}

.feature-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.card-header {
  display: flex;
  align-items: center;
  font-weight: bold;
  font-size: 1.2rem;
  padding: 15px 20px;
  background-color: transparent;
  border-bottom: 1px solid #e8e8e8;
}

.card-icon {
  margin-right: 12px;
  font-size: 1.6rem;
  color: #4CAF50;
  transition: all 0.3s;
}

.feature-card:hover .card-icon {
  transform: scale(1.2);
}

.card-content {
  padding: 20px;
  min-height: 160px;
}

.card-content p {
  color: #666;
  margin-bottom: 15px;
  font-size: 0.95rem;
}

.feature-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feature-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background-color: rgba(76, 175, 80, 0.05);
  border-radius: 6px;
  transition: all 0.3s;
  border-left: 3px solid transparent;
}

.feature-item:hover {
  background-color: rgba(76, 175, 80, 0.1);
  border-left-color: #4CAF50;
  transform: translateX(5px);
}

.feature-item i {
  margin-right: 10px;
  color: #4CAF50;
  font-size: 1.1rem;
}

.feature-item span {
  font-size: 0.95rem;
  color: #555;
}

.card-footer {
  padding: 15px 20px;
  text-align: right;
  border-top: 1px solid #e8e8e8;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
}

.card-footer.active {
  opacity: 1;
  transform: translateY(0);
}

.card-footer .el-button {
  color: #4CAF50;
  font-weight: 500;
}

.welcome-section {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 10px;
  margin-top: 30px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.welcome-text {
  font-size: 1.1rem;
  line-height: 1.7;
  color: #555;
  max-width: 800px;
  margin: 0 auto 20px;
  position: relative;
  z-index: 2;
}

.floating-code {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Courier New', monospace;
  font-size: 1.5rem;
  color: rgba(76, 175, 80, 0.05);
  z-index: 1;
  overflow: hidden;
}

.floating-code span {
  display: inline-block;
  animation: floatUp 4s ease-in-out infinite;
}

/* 动画效果 */
@keyframes float {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(5deg);
  }
}

@keyframes floatUp {
  0%, 100% {
    transform: translateY(0);
    opacity: 0.05;
  }
  50% {
    transform: translateY(-20px);
    opacity: 0.1;
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.9;
  }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .platform-title {
    font-size: 2rem;
  }
  
  .subtitle {
    font-size: 1.1rem;
  }
  
  .feature-cards {
    grid-template-columns: 1fr;
  }
}
</style>